<?php
require ('include/connect.php');
require ('include/db_sql.php');
require ('include/functions.php');
require LoadLang('f.php');
if (isset($_GET['action'])) {
    $action = $_GET['action'];
}
if (empty($action)) {
    $action = $_POST['action'];
}
// 非登陆操作检测是否登陆
if ($action != "login") {
    $lur = islogin();
    $loginin = $lur['username'];
    $rnd = $lur['rnd'];
}
if ($action == "SetDb" || $action == "DoRep" || $action == "DoOpi" || $action == "DoDrop" || $action == "DropDb" || $action == "CreateDb" || $action == "EmptyTable" || $action == "DoSave" || $action == "DoDelSave" || $action == "DelBakpath" || $action == "DelZip" || $action == "DoExecSql" || $action == "DoTranExecSql" || $action == "RepPathFiletext" || $action == 'ReplaceTable') {
    include ("include/combakfun.php");
}
if ($action != "SetDb" && $action != "login" && $action != "exit") {
    $link = db_connect();
    $dblink = new mysqlquery();
}
if ($action == "SetDb") // 参数设置
{
    SetDb($_POST);
} elseif ($action == "DoRep") // 修复表
{
    $tablename = $_POST['tablename'];
    $mydbname = $_POST['mydbname'];
    Rep($tablename, $mydbname);
} elseif ($action == "DoOpi") // 忧化表
{
    $tablename = $_POST['tablename'];
    $mydbname = $_POST['mydbname'];
    Opi($tablename, $mydbname);
} elseif ($action == "DoDrop") // 删除表
{
    $tablename = $_POST['tablename'];
    $mydbname = $_POST['mydbname'];
    Drop($tablename, $mydbname);
} elseif ($action == "ReplaceTable") // 替换表
{
    $tablename = $_POST['tablename'];
    $mydbname = $_POST['mydbname'];
    $oldpre = $_POST['oldtablepre'];
    $newpre = $_POST['newtablepre'];
    ReplaceTable($tablename, $oldpre, $newpre, $mydbname);
} elseif ($action == "DropDb") // 删除数据库
{
    $mydbname = $_GET['mydbname'];
    DropDb($mydbname);
} elseif ($action == "CreateDb") // 建立数据库
{
    $mydbname = $_POST['mydbname'];
    $mydbchar = $_POST['mydbchar'];
    CreatDb($mydbname, $mydbchar);
} elseif ($action == "EmptyTable") // 清空表
{
    $tablename = $_POST['tablename'];
    $mydbname = $_POST['mydbname'];
    EmptyTable($tablename, $mydbname);
} elseif ($action == "exit") // 退出系统
{
    LoginOut();
} elseif ($action == "login") // 登陆
{
    $lusername = $_POST['lusername'];
    $lpassword = $_POST['lpassword'];
    if (isset($_POST['key'])) {
        $key = $_POST['key'];
    } else {
        $key = '';
    }
    login($lusername, $lpassword, $key);
} elseif ($action == "DelBakpath") // 删除备份目录
{
    $path = $_GET['path'];
    DelBakpath($path);
} elseif ($action == "DelZip") // 删除压缩包
{
    $f = $_GET['f'];
    DelZip($f);
} elseif ($action == "DoZip") // 压缩目录
{
    $p = $_GET['p'];
    Dozip($p);
} elseif ($action == "DoExecSql") // 执行sql
{
    DoExecSql($_POST);
} elseif ($action == "DoTranExecSql") // 上传执行sql
{
    $file = $_FILES['file']['tmp_name'];
    $file_name = $_FILES['file']['name'];
    $file_type = $_FILES['file']['type'];
    $file_size = $_FILES['file']['size'];
    DoTranExecSql($file, $file_name, $file_type, $file_size, $_POST);
} elseif ($action == "DoSave") // 保存设置
{
    SaveSeting($_POST);
} elseif ($action == "DoDelSave") // 删除设置
{
    DelSeting($_GET);
} elseif ($action == "SetGotoBak") // 设置转向
{
    $savename = $_GET['savename'];
    SetGotoBak($savename);
} elseif ($action == "PathGotoRedata") // 目录转向
{
    $mypath = $_GET['mypath'];
    PathGotoRedata($mypath);
} elseif ($action == "RepPathFiletext") // 替换目录文件
{
    RepPathFiletext($_POST);
} else {
    printerror("ErrorUrl", "history.go(-1)");
}